package com.example.rvdemo.simple;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.rvdemo.R;

import java.util.ArrayList;
import java.util.List;

public class RVSimpleActivity extends Activity {
    private RecyclerView rv_simple;
    private List<String> datalist;
    private RVSimpleAdaptar rvSimpleAdaptar;
    private RadioGroup btn_group_simple;
    private RadioButton rb_vertical,rb_grid,rb_stage;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rv_siimple);
        rv_simple = findViewById(R.id.rv_simple);
        btn_group_simple = findViewById(R.id.btn_group_simple);
        rb_vertical = findViewById(R.id.rb_vertical);
        rb_vertical.setChecked(true);
        rb_grid = findViewById(R.id.rb_grid);
        rb_stage = findViewById(R.id.rb_stage);
        rv_simple.setLayoutManager(new LinearLayoutManager(this));
        datalist = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            datalist.add("I am "+i);
        }
        rvSimpleAdaptar = new RVSimpleAdaptar(this,datalist);
        rv_simple.setAdapter(rvSimpleAdaptar);
        btn_group_simple.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rb_vertical:
                        rv_simple.setLayoutManager(new LinearLayoutManager(RVSimpleActivity.this));
//                        rv_simple.setLayoutManager(new LinearLayoutManager(RVSimpleActivity.this, LinearLayoutManager.HORIZONTAL,false));
                        break;
                    case R.id.rb_stage:
                        rv_simple.setLayoutManager(new StaggeredGridLayoutManager(4,StaggeredGridLayoutManager.VERTICAL));
                        break;
                    case R.id.rb_grid:
                        rv_simple.setLayoutManager(new GridLayoutManager(RVSimpleActivity.this,3));
                        break;
                    default:
                        break;
                }
            }
        });
    }
}
